import { defineStore } from 'pinia'

export const messageStore = defineStore('message', {
    // 存储全局变量
    state: () => ({
        unreadAnnReceivers: [],
        allAnnReceivers: [],

        allConversations: [],
        unreadConversations: []
    }),

    // 计算属性
    getters: {

    },

    // 同步修改状态信息
    actions: {

        // 更新公告列表
        updateUnreadAnnReceivers() {
            this.unreadAnnReceivers = this.allAnnReceivers.filter(ann => ann.readStatus===0)
        },
        //更新未读
        updateUnreadConversations() {
            this.unreadConversations = this.allConversations.filter(convo => convo.isReadCon === 0)
        },

        // 清除所有消息数据
        clearMessages() {
            this.unreadAnnReceivers = []
            this.allAnnReceivers = []
            this.unreadConversations = []
            this.allConversations = []
        }
    },

    // 持久化存储
    persist: {
        enabled: true,
        storage: localStorage,
        paths: ['allAnnReceivers', 'allConversations','unreadConversations','unreadAnnReceivers'] // 只持久化必要的数据
    }
})
